﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbDepartmentTest and is intended
    ///     to contain all TmdbDepartmentTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbDepartmentTest
    {
        /// <summary>
        ///     A test for TmdbDepartment Constructor
        /// </summary>
        [TestMethod]
        public void TmdbDepartmentConstructorTest()
        {
            var target = new TmdbDepartment();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for DepartmentName
        /// </summary>
        [TestMethod]
        public void DepartmentNameTest()
        {
            var target = new TmdbDepartment();
            string expected = Guid.NewGuid().ToString();
            target.DepartmentName = expected;
            string actual = target.DepartmentName;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for JobList
        /// </summary>
        [TestMethod]
        public void JobListTest()
        {
            var target = new TmdbDepartment();
            var expected = new List<string>();
            target.JobList = expected;
            var actual = target.JobList;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\department.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbDepartment();
            var jsonContent = File.ReadAllText( "department.json.txt" );
            var actual = await target.DeserializeJson<TmdbDepartment>( jsonContent );

            Assert.AreEqual( "Directing", actual.DepartmentName );
            Assert.AreEqual( 5, actual.JobList.Count );

            Assert.AreEqual( "Director", actual.JobList[ 0 ] );
            Assert.AreEqual( "Script Supervisor", actual.JobList[ 1 ] );
            Assert.AreEqual( "Other", actual.JobList[ 2 ] );
            Assert.AreEqual( "Layout", actual.JobList[ 3 ] );
            Assert.AreEqual( "Special Guest Director", actual.JobList[ 4 ] );
        }
    }
}